﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>收款记录</title>
    <script src="/js/header.js"></script>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <script src="/lib/date/wdatepicker.js"></script>
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <a class="btn btn-default btn-sm export ReceiptRecord0004 hide gettext" href="javascript:void(0)" data-title="导出">导出</a>
                    <div class="input-group input-group-sm">
                        <div class="input-sm"><input name="autoRefresh" type="checkbox" title="10秒自动刷新" /> <label id="time" class="wd125 gettext">10秒自动刷新</label></div>
                    </div>
                </div>
                <div class="pull-right">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">订单号：</label>
                        <input class="form-control wd125" name="orderNo" type="text" autocomplete="off">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">收款姓名：</label>
                        <input class="form-control wd125" name="cardName" type="text" autocomplete="off">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">通知状态：</label>
                        <select class="form-control gettext" name="noticeStatus">
                            <option value="">请选择</option>
                            <option value="1">未通知</option>
                            <option value="2">通知成功</option>
                            <option value="3">通知失败</option>
                            <option value="4">通知中</option>
                            <option value="5">不通知</option>
                            <option value="-1">排除不通知</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">收款时间：</label>
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" />
                        --<input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" />
                    </div>
                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                    <button type="button" class="btn btn-default btn-sm gettext" id="AdvSearch">高级搜索</button>
                </div>
            </div>
            <!--一高级搜索开始-->
            <div class="AdvSearch">
                <div class="AdvSearchcom collapse">
                    <table>
                        <tbody>
                            <tr>
                                <td class="gettext">公司名称：</td>
                                <td><input class="form-control" name="companyName" type="text" autocomplete="off"></td>
                                <td class="gettext">收款银行：</td>
                                <td><input class="form-control" name="bankName" type="text" autocomplete="off"></td>
                            </tr>
                            <tr>
                                <td class="gettext">客户姓名：</td>
                                <td><input class="form-control" name="withdrawalAccountName" type="text" autocomplete="off"></td>
                                <td></td>
                                <td></td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="AdvSearchfooter t_c">
                        <button id="search" class="btn btn-default btn-sm gettext" type="button">立即搜索</button>
                        <button id="cancel" data-dismiss="modal" class="btn btn-default btn-sm gettext" type="button">取消</button>
                    </div>
                </div>
            </div>
        </form>
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="receiptRecord"></table>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/page/receiptrecord.js?v=201905271107"></script>
    <script type="text/javascript">
        var wait = 10;

        var autoRefresh = $("input[name='autoRefresh']");

        var pageSize = 50;
        $(function () {
            setTime();
            FlashPay.UI.DataAutoHeight();

            FlashPay.UI.Triggerbox({
                btnAdvSearch: '#AdvSearch',
                searchCallBack: function () {
                    doSearch();
                },
                cancelCallBack: function () {

                }
            });

            $("#btnSearch").click(function () {
                FlashPay.UI.DoSearch();
            });

             FlashPay.Util.Ajax({
                type: "POST",
                url: "/Receipt/ReceiptRecordExportAuth",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.success) {
                        if (res.statusCode == 'ReceiptRecord0004') {
                            $("a.ReceiptRecord0004").removeClass("hide");
                        } else {
                            $("a.ReceiptRecord0004").remove();
                        }
                    }
                }
            });

            doSearch();

            $(document).keyup(function (event) {
                var keycode = event.which;
                if (keycode == 13) {
                    FlashPay.UI.DoSearch();
                }
            });

            $(autoRefresh).change(function () {
                time();
            });

            FlashPay.Util.Language();
        });

        //倒时计
        function time() {
            var language = FlashPay.Util.Language();

            var obj = document.getElementById("time");

            var isauto = $(autoRefresh).is(':checked');
            if (!isauto) {

                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = "10 Second Refresh";
                } else {
                    obj.innerText = "10 秒自动刷新";
                }


                return false;
            }

            if (wait == 0) {
                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = "10 Second Refresh";
                } else {
                    obj.innerText = "10秒自动刷新";
                }

                wait = 10;

                if (isauto) {
                    setTimeout(function () { time(); }, 1000);
                }

                FlashPay.UI.DoSearch();
            } else {


                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = wait + " Second Refresh";
                } else {
                    obj.innerText = wait + "秒自动刷新";
                }
                wait--;
                setTimeout(function () { time(); }, 1000);
            }
        }

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function setTime() {
            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(-1) + " 00:00:00");
            $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0) + " 23:59:59");;
            }

        $(".export").click(function () {

            var query = {};


            var orderNo = $("input[name='orderNo']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(orderNo)) {
                query.orderNo = orderNo;
            }

            var cardName = $("input[name='cardName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
                query.cardName = cardName;
            }

            var companyName = $("input[name='companyName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
                query.companyName = companyName;
            }

            var bankName = $("input[name='bankName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(bankName)) {
                query.bankName = bankName;
            }

            var withdrawalAccountName = $("input[name='withdrawalAccountName']").val();
            if (!FlashPay.Util.isNullOrEmptySpance(withdrawalAccountName)) {
                query.withdrawalAccountName = withdrawalAccountName;
            }

            var noticeStatus = $("select[name='noticeStatus']").find("option:selected").val();
            if (!FlashPay.Util.isNullOrEmptySpance(noticeStatus)) {
                query.noticeStatus = noticeStatus;
            }

            query.startTime = $("input[name='startTime']").val();
            query.endTime = $("input[name='endTime']").val();

            FlashPay.UI.Confirm({
                content: "下载收款记录需要花费大量时间,确认要下载吗？",
                ok: function () {
                    var cover = FlashPay.UI.Mask({
                        obj: $("body"),
                        opacity: 0.5
                    });

                    FlashPay.Util.Ajax({
                        url: '/Receipt/GetReceiptRecordsExport',
                        type: 'POST',
                        data: { query: query },
                        success: function (response) {
                            if (response.success) {
                                cover.Remove();

                                if (response.data != null && response.data.length > 0) {
                                    var body = '<table>';

                                    body += '<tr>';
                                    body += '<td>订单号</td>';
                                    body += '<td>公司名称</td>';
                                    body += '<td>收款单号</td>';
                                    body += '<td>收款银行</td>';
                                    body += '<td>收款姓名</td>';
                                    body += '<td>收款卡号</td>';
                                    body += '<td>创建时间</td>';
                                    body += '<td>收款金额</td>';
                                    body += '<td>收款时间</td>';
                                    body += '<td>交易类型</td>';
                                    body += '<td>通知状态</td>';
                                    body += '<td>通知时间</td>';
                                    body += '<td>通知次数</td>';
                                    body += '<td>客户姓名</td>';
                                    body += '<td>客户银行</td>';
                                    body += '<td>客户卡号</td>';
                                    body += '<td>客户附言</td>';
                                    body += '</tr>';

                                    $.each(response.data, function (i, item) {
                                        body += '<tr>';
                                        body += '<td>' + item.orderNo + '</td>';
                                        body += '<td>' + item.companyName + '</td>';
                                        body += '<td>' + item.withdrawalOrderNo + '</td>';
                                        body += '<td>' + item.bankName + '</td>';
                                        body += '<td>' + item.cardName + '</td>';
                                        body += '<td>' + item.cardNumber + '</td>';
                                        body += '<td>' +  FlashPay.Util.FormatDate(item.createDbdate) + '</td>';
                                        body += '<td>' + item.withdrawalAmount + '</td>';
                                        body += '<td>' +  FlashPay.Util.FormatDate(item.depositDate) + '</td>';
                                        body += '<td>' + item.depositType + '</td>';
                                        body += '<td>' + item.noticeStatusString + '</td>';
                                        body += '<td>' + item.noticeLastDate + '</td>';
                                        body += '<td>' + item.noticeTimes + '</td>';
                                        body += '<td>' + item.withdrawalAccountName + '</td>';
                                        body += '<td>' + item.withdrawalBankName + '</td>';
                                        body += '<td>' + item.withdrawalCardNumber + '</td>';
                                        body += '<td>' + item.postScript + '</td>';
                                        body += '</tr>';
                                    });

                                    body += '</table>';

                                    var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                    excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                    excelFile += "<head>";
                                    excelFile += "<!--[if gte mso 9]>";
                                    excelFile += "<xml>";
                                    excelFile += "<x:ExcelWorkbook>";
                                    excelFile += "<x:ExcelWorksheets>";
                                    excelFile += "<x:ExcelWorksheet>";
                                    excelFile += "<x:Name>";
                                    excelFile += "Sheet1";
                                    excelFile += "</x:Name>";
                                    excelFile += "<x:WorksheetOptions>";
                                    excelFile += "<x:DisplayGridlines/>";
                                    excelFile += "</x:WorksheetOptions>";
                                    excelFile += "</x:ExcelWorksheet>";
                                    excelFile += "</x:ExcelWorksheets>";
                                    excelFile += "</x:ExcelWorkbook>";
                                    excelFile += "</xml>";
                                    excelFile += "<![endif]-->";
                                    excelFile += "</head>";
                                    excelFile += "<body>";
                                    excelFile += body;
                                    excelFile += "</body>";
                                    excelFile += "</html>";

                                    var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
                                    var link = document.createElement("a");
                                    link.href = uri;

                                    link.style = "visibility:hidden";
                                    link.download = response.statusCode + ".xlsx";

                                    document.body.appendChild(link);
                                    link.click();
                                    document.body.removeChild(link);
                                }
                                else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("暂无记录");
                                }

                            } else {
                                cover.Remove();
                                FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                            }
                        },
                        error: function (json) {
                            cover.Remove();
                            FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        }
                    });
                }
            });
    });
    </script>
</body>
</html>